<template>
  <Modal v-model:visible="visible" :title="title" @cancel="close">
    <template #footer>
      <Button key="submit" type="primary" @click="submit">确认</Button>
      <Button key="back" @click="close">取消</Button>
    </template>
    <Form :model="formState" v-bind="formItemLayout" ref="formRef">
      <FormItem label="审核结果" name="action">
        <RadioGroup v-model:value="formState.action" name="radioGroup">
          <Radio value="pass">通过</Radio>
          <Radio value="rejected">未通过</Radio>
        </RadioGroup>
      </FormItem>
      <FormItem
        v-if="formState.action == 'rejected'"
        label="原因"
        name="rejectedReason"
        :rules="[{ required: true, message: '请输入不通过原因' }]"
      >
        <Textarea v-model:value="formState.rejectedReason"></Textarea>
      </FormItem>
    </Form>
  </Modal>
</template>
<script lang="ts" setup>
import { Modal, Form, RadioGroup, Radio, FormItem, Textarea, message, Button } from 'ant-design-vue';
import { ref } from 'vue';
import { auditEntApp } from '/@/api/tenant-mgmt/enterpriseAppManagement/enterpriseAppManagement';
import { auditEntMgt } from '/@/api/tenant-mgmt/enterpriseManagement/enterpriseManagement';
import { AuditEntMgtParam } from '/@/api/tenant-mgmt/enterpriseManagement/model/enterpriseManagementModel';
const visible = ref(false);
let formState = ref({} as AuditEntMgtParam);
const formRef = ref();
const title = ref();
const openAudit = (record, auditTitle) => {
  title.value = auditTitle;
  formState.value.id = record.id;
  visible.value = true;
};
const close = () => {
  visible.value = false;
  formRef.value.clearValidate();
  formState.value = {} as AuditEntMgtParam;
};
const emit = defineEmits(['submitSuccess']);
const submit = async () => {
  let res = '';
  let params = formState.value;
  formRef.value.validate().then(async () => {
    if (title.value == '审核企业信息') {
      res = await auditEntMgt(params);
    } else if (title.value == '审核订阅应用') {
      res = await auditEntApp(params);
    }
    if (res) {
      message.success(res);
    }
    emit('submitSuccess');
    close();
  });
};

const formItemLayout = {
  labelCol: { span: 4 },
  wrapperCol: { span: 14 },
};
defineExpose({ openAudit });
</script>
